package code;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

import java.util.*;

/**
 *
 * @author jyotesh
 */
public class CliqueWrapper extends ArrayList<Integer> {
    
    private int[] arity = null;
    private ArrayList<Integer> cliqueNodeList = null;

    public CliqueWrapper(int[] arity, ArrayList<Integer> cliqueNodeList) {
        super();
        this.arity = arity;
        this.cliqueNodeList = cliqueNodeList;
    }
    
    @Override
    public boolean equals(Object obj) {
        if (obj instanceof CliqueWrapper == false)
            return false;
        Integer[] thisClique = new Integer[this.size()];
        this.toArray(thisClique);
        Integer[] otherClique = new Integer[((CliqueWrapper)obj).size()];
        ((CliqueWrapper)obj).toArray(otherClique);
        Arrays.sort(thisClique);
        Arrays.sort(otherClique);
        return Arrays.equals(thisClique, otherClique);
    }

    @Override
    public int hashCode() {
        int hash, multiplier;
        hash = 0;
        multiplier = 1;
        for (int i = this.size() - 1; i >= 0; i--) {
            hash += this.get(i) * multiplier;
            multiplier *= arity[cliqueNodeList.get(i)];
        }
        return hash;
    }
}
